
//
// Copyright 2009 Arne Halvorsen (arne.halvorsen@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Project page: http://code.google.com/p/mf4j/

//
// 091120a- aha42 - Created.
// 091120b- aha42 - Fixed spelling error in checkPrivacyFilter method name.
// 091120c- aha42 - Minor jdoc fix.
// 091121a- aha42 - isSessionArg(String).
// 091121b- aha42 - Added project page link (google code) to header comment.
// 091124 - aha42 - Removed check on 'secret' as illegal argument in 
//                  isSession(String) : There is no such proper argument.
// 091210 - aha42 - IOException -> FlickrException.
//

package org.aha.mf4j;

import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 *   Utility methods of use when working with Flickr API method arguments.
 * </p>
 * @author Arne Halvorsen (aha42).
 */
public final class FlickrMethodArguments 
{
  // Utility pattern dictates private constructor.
  private FlickrMethodArguments(){}
  
    /**
     * <p>
     *   Checks if the {@code media} parameter value is valid.
     * </p>
     * @param media Value.
     * @throws IllegalArgumentException If not valid media value.
     */
  public static void checkMedia(String media)
  {
    if (media==null)
    {
      throw new NullPointerException("media");
    }
    
    if (media.equals("all") || media.equals("photos") || media.equals("videos"))
      return;
    
    throw new IllegalArgumentException("uknown media : "+media);
  }
  
  /**
   * <p>
   *   Checks if the {@code privacy_filter} parameter value is valid.
   * </p>
   * @param privacyFilter Value.
   * @throws IllegalArgumentException If not valid media value.
   */
  public static void checkPrivacyFilter(String privacyFilter)
  {
    if (privacyFilter==null)
    {
      throw new NullPointerException("privacyFilter");
    }
    
    if (privacyFilter.length()==1)
    {
      switch (privacyFilter.charAt(0))
      {
        case '1' :
        case '2' :
        case '3' :
        case '4' :
        case '5' : return;
      }
    }    
    throw new IllegalArgumentException("uknown privacy filter : "+
      privacyFilter);
  }
  
  private static final Set<String> c_sessionArg=new HashSet<String>();
  
  static
  {
    c_sessionArg.add(("auth_token"));          
    c_sessionArg.add(("api_key"));  
    c_sessionArg.add(("method"));
  }
  
  /**
   * <p>
   *   Tells if {@code name} is a name on one of the 
   *   {@link Request} parameters it is a 
   *   {@link FlickrSession} responsible to set and should not be set by client
   *   code.
   * </p>
   * @param name Parameter name.
   * @return {@code true} if {@code name} is {@code auth_token}, 
   *         {@code api_key}, or {@code method}.
   */
  public static boolean isSessionArg(String name)
  {
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    
    return c_sessionArg.contains(name);    
  }
  
}
